/**
 * Created by gongxun on 17/1/4.
 */

var KwxTableRecordCardLayer = GameCCSBase.extend({
    Image_bg : null,
    mRecordCardInfo : null,
    ctor: function () {
        this._super();
        this.loadCocostudio("res/ccs/KwxTableRecordCard.json");
        this.Image_bg = mo.seekWidgetByName(this.ccsNode, "Image_bg");

        this.Image_bg.setVisible(false);

        mo.seekWidgetByName(this.ccsNode, "Button_record").addTouchEventListener(function(sender, type){
            if (type == ccui.Widget.TOUCH_BEGAN){
                this.Image_bg.setVisible(true);
                this.updateRecordCard();
            }else if (type == ccui.Widget.TOUCH_MOVED){

            }else{
                this.Image_bg.setVisible(false);
            }
        }, this);
        mo.seekWidgetByName(this.ccsNode, "Button_record").setVisible(false);

        this.loadUI();
    },

    onEnter : function(){
        this._super();

        mo.eventHelper.add("TableStatskwxChange", this, function(){
            this.updateRecordCard();
        });
    },

    onExit : function(){
        mo.eventHelper.remove(this);
        this._super();
    },

    loadUI : function(){
        this.mRecordCardInfo = [];

        for (var i = 0; i < 21; i++){
            var item = {num:0, ui:null};

            var index = 0;

            //num
            item.num = 0;
            if (i < 9){
                //条
                index = i;
                item.num = index + 21;
            }else if (i < 18){
                //筒
                index = i - 9;
                item.num = index + 41;
            }else{
                //万
                index = i - 18;
                item.num = index + 85;
            }

            //ui
            item.ui = mo.seekWidgetByName(this.ccsNode, "AtlasLabel_num" + item.num);

            //pos
            item.ui.setPositionX(index * 65 + 61);

            this.mRecordCardInfo.push(item);
        }
    },

    updateRecordCard : function(){
        if (this.Image_bg.isVisible()){
            //打开的时候才触发
            for (var i = 0; i < this.mRecordCardInfo.length; i++){
                var item = this.mRecordCardInfo[i];
                var left = mo.kwxTableStatus.getLeftCardCount(item.num);
                item.ui.setString("" + left);
            }
        }
    }
});